
		set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

ALTER TRIGGER [ProjectExpensesOnUpdate] 
   ON  [dbo].[ProjectExpenses] 
   AFTER Update
AS 
	declare @tablePrimaryKey ProjectCodeType
	declare @UpdateBy nvarchar(50)
	declare @UpdateIP nvarchar(50)
	declare @UpdateDate datetime
	
	select @tablePrimaryKey = [ProjectCode] from inserted
	select @UpdateBy = [UpdateBy] from inserted
	select @UpdateIP = [UpdateIP] from inserted
	select @UpdateDate = [UpdateDate] from inserted
	

if (update([ProjectCode]))
 begin
  declare @NewProjectCode ProjectCodeType
  declare @OldProjectCode ProjectCodeType

  select @OldProjectCode = [ProjectCode] from Deleted
  select @NewProjectCode = [ProjectCode] from inserted
if( @OldProjectCode != @NewProjectCode)
begin
	INSERT INTO [dbo].[DBF_UPDATES]
           ([Column],[TableName],[ReferenceID],[NewValue],[OldValue],[UpdateBy],[UpdateIP],[UpdatedTime])
     VALUES
           ('ProjectCode','ProjectExpenses',@tablePrimaryKey,@NewProjectCode,@OldProjectCode,@UpdateBy,@UpdateIP,@UpdateDate)
end
end

if (update([InvoiceNumber]))
 begin
  declare @NewInvoiceNumber NumType
  declare @OldInvoiceNumber NumType

  select @OldInvoiceNumber = [InvoiceNumber] from Deleted
  select @NewInvoiceNumber = [InvoiceNumber] from inserted
if( @OldInvoiceNumber != @NewInvoiceNumber)
begin
	INSERT INTO [dbo].[DBF_UPDATES]
           ([Column],[TableName],[ReferenceID],[NewValue],[OldValue],[UpdateBy],[UpdateIP],[UpdatedTime])
     VALUES
           ('InvoiceNumber','ProjectExpenses',@tablePrimaryKey,@NewInvoiceNumber,@OldInvoiceNumber,@UpdateBy,@UpdateIP,@UpdateDate)
end
end

if (update([ReferenceDate]))
 begin
  declare @NewReferenceDate DateType
  declare @OldReferenceDate DateType

  select @OldReferenceDate = [ReferenceDate] from Deleted
  select @NewReferenceDate = [ReferenceDate] from inserted
if( @OldReferenceDate != @NewReferenceDate)
begin
	INSERT INTO [dbo].[DBF_UPDATES]
           ([Column],[TableName],[ReferenceID],[NewValue],[OldValue],[UpdateBy],[UpdateIP],[UpdatedTime])
     VALUES
           ('ReferenceDate','ProjectExpenses',@tablePrimaryKey,@NewReferenceDate,@OldReferenceDate,@UpdateBy,@UpdateIP,@UpdateDate)
end
end

if (update([ChargeFrom]))
 begin
  declare @NewChargeFrom NameType
  declare @OldChargeFrom NameType

  select @OldChargeFrom = [ChargeFrom] from Deleted
  select @NewChargeFrom = [ChargeFrom] from inserted
if( @OldChargeFrom != @NewChargeFrom)
begin
	INSERT INTO [dbo].[DBF_UPDATES]
           ([Column],[TableName],[ReferenceID],[NewValue],[OldValue],[UpdateBy],[UpdateIP],[UpdatedTime])
     VALUES
           ('ChargeFrom','ProjectExpenses',@tablePrimaryKey,@NewChargeFrom,@OldChargeFrom,@UpdateBy,@UpdateIP,@UpdateDate)
end
end

if (update([Description]))
 begin
  declare @NewDescription DescriptionType
  declare @OldDescription DescriptionType

  select @OldDescription = [Description] from Deleted
  select @NewDescription = [Description] from inserted
if( @OldDescription != @NewDescription)
begin
	INSERT INTO [dbo].[DBF_UPDATES]
           ([Column],[TableName],[ReferenceID],[NewValue],[OldValue],[UpdateBy],[UpdateIP],[UpdatedTime])
     VALUES
           ('Description','ProjectExpenses',@tablePrimaryKey,@NewDescription,@OldDescription,@UpdateBy,@UpdateIP,@UpdateDate)
end
end

if (update([ServiceCharge]))
 begin
  declare @NewServiceCharge GenericDecimalType
  declare @OldServiceCharge GenericDecimalType

  select @OldServiceCharge = [ServiceCharge] from Deleted
  select @NewServiceCharge = [ServiceCharge] from inserted
if( @OldServiceCharge != @NewServiceCharge)
begin
	INSERT INTO [dbo].[DBF_UPDATES]
           ([Column],[TableName],[ReferenceID],[NewValue],[OldValue],[UpdateBy],[UpdateIP],[UpdatedTime])
     VALUES
           ('ServiceCharge','ProjectExpenses',@tablePrimaryKey,@NewServiceCharge,@OldServiceCharge,@UpdateBy,@UpdateIP,@UpdateDate)
end
end

if (update([OwnerGroupID]))
 begin
  declare @NewOwnerGroupID GroupIDType
  declare @OldOwnerGroupID GroupIDType

  select @OldOwnerGroupID = [OwnerGroupID] from Deleted
  select @NewOwnerGroupID = [OwnerGroupID] from inserted
if( @OldOwnerGroupID != @NewOwnerGroupID)
begin
	INSERT INTO [dbo].[DBF_UPDATES]
           ([Column],[TableName],[ReferenceID],[NewValue],[OldValue],[UpdateBy],[UpdateIP],[UpdatedTime])
     VALUES
           ('OwnerGroupID','ProjectExpenses',@tablePrimaryKey,@NewOwnerGroupID,@OldOwnerGroupID,@UpdateBy,@UpdateIP,@UpdateDate)
end
end

if (update([IsDelete]))
 begin
  declare @NewIsDelete bit
  declare @OldIsDelete bit

  select @OldIsDelete = [IsDelete] from Deleted
  select @NewIsDelete = [IsDelete] from inserted
if( @OldIsDelete != @NewIsDelete)
begin
	INSERT INTO [dbo].[DBF_UPDATES]
           ([Column],[TableName],[ReferenceID],[NewValue],[OldValue],[UpdateBy],[UpdateIP],[UpdatedTime])
     VALUES
           ('IsDelete','ProjectExpenses',@tablePrimaryKey,@NewIsDelete,@OldIsDelete,@UpdateBy,@UpdateIP,@UpdateDate)
end
end

